package com.data.app.service.impl;

import com.css.bpm.platform.utils.PlatformSessionUtils;
import com.data.app.commons.constant.CommonConstant;
import com.data.app.commons.constant.dto.RestResultData;
import com.data.app.commons.division.DivisionUtils;
import com.data.app.commons.utils.Entityutils;
import com.data.app.dao.pg.*;
import com.data.app.dao.primary.*;
import com.data.app.pojo.pg.*;
import com.data.app.pojo.primary.*;
import com.data.app.service.ShareDataDisasterService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.PostConstruct;
import java.awt.geom.Point2D;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Service
public class ShareDataDisasterServiceImpl implements ShareDataDisasterService {
    @Autowired
    CityHouseBaseDao cityHouseBaseDao;
    @Autowired
    CountryDlHouseBaseDao countryDlHouseBaseDao;
    @Autowired
    CountryJhHouseBaseDao countryJhHouseBaseDao;
    @Autowired
    CityHouseNonBaseDao cityHouseNonBaseDao;
    @Autowired
    CountryNoHouseBaseDao countryNoHouseBaseDao;
    @Autowired
    YhDisasterDao yhDisasterDao;
    @Autowired
    private DivisionUtils divisionUtils;
    @Autowired
    private YhDisasterBaseDao yhDisasterBaseDao;
    @Autowired
    private QhSiteClassResultBaseDao qhSiteClassResultBaseDao;
    @Autowired
    private WaterFacilityBaseDao waterFacilityBaseDao;
    @Autowired
    BridgeBaseDao bridgeBaseDao;
    @Autowired
    HddcActivefaultDao hddcActivefaultDao;
    @Autowired
    FiveMapPGABaseDao fiveMapPGABaseDao;


    /**
     * 全局数据集
     */
    private static List<Map<String, List<String>>> mapList = new ArrayList<>();
    private static Map<String, List<String>> map = new HashMap<>();
    // private static Map<String,List<Object[]>> yhCodeAndYhProjectTypesAll = new HashMap<>();
    // private static List<Object[]> yhCodeAndYhProjectTypes = new ArrayList<>();
    private static Map<String, Object> divisionInfoMap = new HashMap<>();
    public static Map<String, HashMap<List, String>> sitetypesAll = new HashMap<>();
    public static HashMap<List, String> sitetypes = new HashMap<>();
    private static Map<String, List<String[]>> activespacedatas = new HashMap<>();
    private static Map<List, String> fiveMapPGAdatas = new HashMap<>();

    @Value("${transactional.commit.size:10000}")
    private int commitSize;
    //查询的时间范围
    @Value("${query.date.begin}")
    private String begin;
    @Value("${query.date.end}")
    private String end;

    @Value("${query.date.a:0}")
    private int a;

    @Value("${query.date.b:200000}")
    private int b;
    private Logger logger = LoggerFactory.getLogger(getClass());


    @PostConstruct
    public void init() {
        // yhCodeAndYhProjectTypes = yhDisasterBaseDao.findYhCodeAndYhProjectTypeByIsValid();
        divisionInfoMap = divisionUtils.findDivisionNameAndDivisionCode();
        List<Object[]> sitClassAndCoordinatesAll = qhSiteClassResultBaseDao.findSitClassAndCoordinatesAll();
        Map<String, List<Object[]>> listMap = new HashMap<>();
        List<Object[]> objects1 = null;
        for (Object[] objects : sitClassAndCoordinatesAll) {
            if (listMap.size() == 0) {
                objects1 = new ArrayList<>();
                objects1.add(objects);
                listMap.put((String) objects[2], objects1);
            } else {
                if (listMap.containsKey((String) objects[2])) {
                    objects1 = listMap.get(objects[2]);
                    objects1.add(objects);
                } else {
                    objects1 = new ArrayList<>();
                    objects1.add(objects);
                    listMap.put((String) objects[2], objects1);
                }
            }
        }
        for (String province : listMap.keySet()) {
            // yhCodeAndYhProjectTypesAll.put(province, yhDisasterDao.findYhCodeAndYhProjectTypeByIsValid(province));
            List<Object[]> sitClassAndCoordinates = listMap.get(province);
            for (Object[] objects : sitClassAndCoordinates) {
                setBaseDatas(objects[0].toString(), objects[1].toString());
            }
            sitetypesAll.put(province, sitetypes);
            sitetypes.clear();
        }
        List<Object[]> allActiveFaultDatas = hddcActivefaultDao.findAllActiveFaultDatas();
        Map<String, List<String>> tempdatas = new HashMap<>();
        for (Object[] objects : allActiveFaultDatas) {
            String key = (String) objects[2];
            List<String> list = null;
            if (!tempdatas.containsKey(key)) {
                list = new ArrayList<>();
            } else {
                list = tempdatas.get(key);
            }
            list.add((String) objects[1]);
            tempdatas.put(key, list);
        }
        for (String key : tempdatas.keySet()) {
            List<String[]> strList = new ArrayList<>();
            List<String> list = tempdatas.get(key);
            for (String str : list) {
                String[] singlines = str.split("#");
                for (int i = 0; i < singlines.length; i++) {
                    String[] points = singlines[i].split(";");
                    for (int j = 0; j < points.length; j++) {
                        String[] lonlats = points[j].split(",");
                        if (lonlats.length == 2) {
                            strList.add(lonlats);
                        }
                    }
                }
            }
            activespacedatas.put(key, strList);
        }
        List<Object[]> allFiveMapPGADatas = fiveMapPGABaseDao.findAllFiveMapPGADatas();
        for (Object[] object : allFiveMapPGADatas) {
            String stype = object[1].toString();
            String sspace = object[2].toString();
            setFiveMapPGADatas(stype, sspace);
        }

    }

    public static void setFiveMapPGADatas(String stype, String sspace) {
        String dtype = CommonConstant.SFLD_70;
        Double doubleType = Double.parseDouble(stype);
        if (doubleType == 0.05) {
            dtype = CommonConstant.SFLD_6;
        } else if (doubleType == 0.15) {
            dtype = CommonConstant.SFLD_75;
        } else if (doubleType == 0.2) {
            dtype = CommonConstant.SFLD_82;
        } else if (doubleType == 0.3) {
            dtype = CommonConstant.SFLD_83;
        } else if (doubleType == 0.4) {
            dtype = CommonConstant.SFLD_94;
        }
        /*if(stype=="0.05"){
            dtype=CommonConstant.SFLD_6;
        }else if(stype=="0.15"){
            dtype=CommonConstant.SFLD_75;
        }else if(stype=="0.2"){
            dtype=CommonConstant.SFLD_82;
        }else if(stype=="0.3"){
            dtype=CommonConstant.SFLD_83;
        }else if(stype=="0.4"){
            dtype=CommonConstant.SFLD_94;
        }*/

        String dspace = "";
        sspace = sspace.replace(")), ((", "#");
        sspace = sspace.replace("), (", "#");
        String[] ss1 = sspace.split("\\(");
        if (ss1.length >= 2) {
            String[] ss2 = ss1[ss1.length - 1].split("\\)");
            if (ss2.length <= 2) {
                dspace = ss2[0].replace(",", ";").replace("; ", ";").replace(" ", ",");
            }
        }
        if (dspace == "") {
            return;
        }
        String[] spacedatas = dspace.split("#");

        for (int i = 0; i < spacedatas.length; i++) {
            String[] lonlats = spacedatas[i].split(";");
            List<Point2D.Double> points = new ArrayList<>();
            if (lonlats.length > 0) {
                for (int j = 0; j < lonlats.length; j++) {
                    String[] lonlat = lonlats[j].split(",");
                    if (lonlat.length != 2) {
                        continue;
                    }
                    Point2D.Double point = new Point2D.Double();
                    point.setLocation(Double.parseDouble(lonlat[0]), Double.parseDouble(lonlat[1]));
                    points.add(point);
                }
                fiveMapPGAdatas.put(points, dtype);
            }
        }

        /*fiveMapPGAdatas.put(points,dtype);*/
    }

    /**
     * risk_census_city_house城镇住宅
     *
     * @return
     */
    @Override
    public RestResultData shareDataCityHouse() {
        List<CityHouseEntity> newData = null;
        List<CityHouseEntity> updateData = null;
        // 日期格式yyyy-MM-dd ，为0则为当日，1则是全部数据,否则指定日期查询
        // Arrays.asList("110000","130000","140000","150000","210000","220000","230000","310000",
        //         "320000","350000","360000","370000","410000","420000","430000","440000","450000","460000","530000",
        //         "540000","610000","650000","660000")
        for (String city1 : Arrays.asList("660000")) {
            if ("1".equals(begin)) {
                System.out.println("--------city:{}" + city1);
                newData = cityHouseBaseDao.findAllByLimit(city1);
            } else {
                LocalDate beginDate = null;
                LocalDate endDate = null;
                if ("0".equals(begin)) {
                    beginDate = LocalDate.now();
                    endDate = LocalDate.now();
                } else {
                    // 根据时间段查询数据
                    beginDate = LocalDate.parse(begin, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    endDate = LocalDate.parse(end, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                }
                newData = cityHouseBaseDao.findCityHouseAddByDate(beginDate, endDate);
                updateData = cityHouseBaseDao.findCityHouseUpdateByDate(beginDate, endDate);
            }
            if (CollectionUtils.isEmpty(newData) && CollectionUtils.isEmpty(updateData)) {
                System.out.println(city1 + "城镇住宅没有数据更新");
                continue;
            }
            //newData=newData.subList(a,b);
            //新增
            if (!CollectionUtils.isEmpty(newData)) {
                // List<YhDisastersEntity> yhDisasterEntities = new ArrayList<>();
                List<YhDisasterEntity> yhDisasterEntities = new ArrayList<>();
                int count = 0;
                Long start = System.currentTimeMillis();
                for (CityHouseEntity cityHouse : newData) {
                    // YhDisasterEntity yhDisaster = new YhDisaster37Entity11();
                    YhDisasterEntity yhDisaster = Entityutils.getEntity(cityHouse.getProvince());
                    yhDisaster.setId(UUID.randomUUID().toString().replace("-", ""));
                    yhDisaster.setYhCode(cityHouse.getBh());
                    yhDisaster.setYhUnit(cityHouse.getMc());
                    yhDisaster.setExtends4(cityHouse.getJzmc());
                    yhDisaster.setYhProjectType(CommonConstant.PROJECT_TYPE_HOUSE);
                    //List<YhDisastersEntity> disaster = yhDisasterBaseDao.findByYhCodeAndIsValidAndYhProjectType(cityHouse.getBh(), "1", yhDisaster.getYhProjectType());
                    //验重
                    // boolean isRRepeat = false;
                    // for (Object[] yhCodeAndYhProjectType : yhCodeAndYhProjectTypes) {
                    //     if (yhCodeAndYhProjectType[0].toString().equals(cityHouse.getBh()) &&
                    //             yhCodeAndYhProjectType[1].toString().equals(CommonConstant.PROJECT_TYPE_HOUSE)) {
                    //         isRRepeat = true;
                    //         //logger.info("城镇住宅数据重复，重复编码:{}", cityHouse.getBh());
                    //         break;
                    //     }
                    // }
                    // if (isRRepeat) continue;
                    //yhDisaster.setProvince(divisionUtils.getDicisionNameByCode(cityHouse.getProvince()));
                    yhDisaster.setProvince(divisionInfoMap.get(cityHouse.getProvince()).toString());
                    String city = cityHouse.getCity();
                    if (city.equals("110100") || city.equals("120100") || city.equals("310100") || city.equals("500100")) {
                        city = city.substring(0, 2) + "0000";
                    }
                    yhDisaster.setCity(divisionInfoMap.get(city).toString());
                    yhDisaster.setArea(divisionInfoMap.get(cityHouse.getDistrict()).toString());
                    yhDisaster.setDetailedAddress(cityHouse.getAddress());
                    String[] lonLat = {"0", "0"};
                    if (Objects.isNull(cityHouse.getShape())) {
                        //throw new ParamServiceException(ServiceErrEnumInfo.NOTFOUND_RESULT_ERR, "空间数据为空");
                    } else {
                        String str = cityHouse.getShape().toString();
                        lonLat = getLonLat(str);//纬度
                        //yhDisaster.setSpaceData(str.split(";")[1]);//空间数据
                        yhDisaster.setSpaceData(str);//空间数据
                        yhDisaster.setLatitude(lonLat[1]);
                        yhDisaster.setLongitude(lonLat[0]);
                    }
                    yhDisaster.setYhConstructionPrice("");//造价
                    if (Objects.isNull(cityHouse.getDcmj())) {
                        yhDisaster.setYhConstructionScale("0");
                    } else {
                        yhDisaster.setYhConstructionScale(cityHouse.getDcmj().toString());//建设规模
                    }
//                yhDisaster.setYhProjectTask(CommonConstant.TYPE_CITY_HOUSE);//工程任务-建筑名称
                    String buildTime = cityHouse.getBuildTime();//建造年代
                    yhDisaster.setBuildingTimeDetails(buildTime);
                    if (StringUtils.isEmpty(buildTime)) {
                        buildTime = CommonConstant.BUILDTIME_NO;
                        yhDisaster.setBuildingTimeDetails("0");
                    } else {
                        Integer integer = 0;
                        if (buildTime.length() >= 4) {
                            integer = Integer.valueOf(buildTime.substring(0, 4));
                        } else {
                            yhDisaster.setYhBuildingTime(CommonConstant.BUILDTIME_NO);
                        }
                        if (integer < 1989) {
                            buildTime = CommonConstant.BUILDTIME_1989;
                        } else if (integer >= 1990 && integer < 2000) {
                            buildTime = CommonConstant.BUILDTIME_1990;
                        } else if (integer >= 2000 && integer <= 2011) {
                            buildTime = CommonConstant.BUILDTIME_2000;
                        } else if (integer > 2011) {
                            buildTime = CommonConstant.BUILDTIME_2011;
                        } else {
                            buildTime = CommonConstant.BUILDTIME_NO;
                        }
                    }
                    yhDisaster.setYhBuildingTime(buildTime);
                    yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_III);//抗震设防类别
                    //原设防烈度
                    String yearthIntensity = null;
                    if (Objects.isNull(cityHouse.getJzsfld())) {
                        yearthIntensity = CommonConstant.SFLD_N0;
                    } else {
                        switch (cityHouse.getJzsfld().intValue()) {
                            case 1:
                                yearthIntensity = CommonConstant.SFLD_N0;
                                break;
                            case 2:
                                yearthIntensity = CommonConstant.SFLD_6;
                                break;
                            case 3:
                                yearthIntensity = CommonConstant.SFLD_70;
                                break;
                            case 4:
                                yearthIntensity = CommonConstant.SFLD_75;
                                break;
                            case 5:
                                yearthIntensity = CommonConstant.SFLD_82;
                                break;
                            case 6:
                                yearthIntensity = CommonConstant.SFLD_83;
                                break;
                            case 7:
                                yearthIntensity = CommonConstant.SFLD_94;
                                break;
                            default:
                                yearthIntensity = CommonConstant.SFLD_N0;
                        }
                    }
                    yhDisaster.setYhEarthIntensity(yearthIntensity);
                    //现设防烈度
                    String nowEarthQh = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    String extends5 = null;
                    if (!Objects.isNull(cityHouse.getMqsfld())) {
                        switch (cityHouse.getMqsfld().intValue()) {
                            case 1:
                                extends5 = CommonConstant.SFLD_N0;
                                break;
                            case 2:
                                extends5 = CommonConstant.SFLD_6;
                                break;
                            case 3:
                                extends5 = CommonConstant.SFLD_70;
                                break;
                            case 4:
                                extends5 = CommonConstant.SFLD_75;
                                break;
                            case 5:
                                extends5 = CommonConstant.SFLD_82;
                                break;
                            case 6:
                                extends5 = CommonConstant.SFLD_83;
                                break;
                            case 7:
                                extends5 = CommonConstant.SFLD_94;
                                break;
                            default:
                                extends5 = CommonConstant.SFLD_N0;
                        }
                    }
                    // if (Objects.isNull(cityHouse.getMqsfld())) {
                    //     //nowEarthQh = CommonConstant.SFLD_70;
                    //     nowEarthQh = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    // } else {
                    //     switch (cityHouse.getMqsfld().intValue()) {
                    //         case 1:
                    //             nowEarthQh = CommonConstant.SFLD_6;
                    //             break;
                    //         case 2:
                    //             nowEarthQh = CommonConstant.SFLD_70;
                    //             break;
                    //         case 3:
                    //             nowEarthQh = CommonConstant.SFLD_75;
                    //             break;
                    //         case 4:
                    //             nowEarthQh = CommonConstant.SFLD_82;
                    //             break;
                    //         case 5:
                    //             nowEarthQh = CommonConstant.SFLD_83;
                    //             break;
                    //         case 6:
                    //             nowEarthQh = CommonConstant.SFLD_94;
                    //             break;
                    //         default:
                    //             //nowEarthQh = CommonConstant.SFLD_70;
                    //             nowEarthQh = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    //     }
                    // }
                    yhDisaster.setYhNowEarthQh(nowEarthQh);//现抗震设防区划
                    yhDisaster.setExtends5(extends5);
                    yhDisaster.setYhFieldType(getSiteTypeFromLonLat(lonLat[0], lonLat[1], yhDisaster.getProvince()) + "类场地");//场地类别默认二类
                    //现存灾害
                    if ("1".equals(cityHouse.getYwlfbxqx())) {//有
                        if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SERIOUS);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_BIG);
                        }
                    } else {
                        if (CommonConstant.BUILDTIME_2011.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_NO);
                        } else if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_COMMON);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SLIGHT);
                        }
                    }
                    yhDisaster.setExtends1(CommonConstant.TYPE_CITY_HOUSE_CH);
                    yhDisaster.setExtends3(cityHouse.getFxpcDataidSjgl());
                    yhDisaster.setQualityResult("1");
                    yhDisaster.setReviewStatus("1");
                    yhDisaster.setYhCreatetime(cityHouse.getFxpcCreatetimeSjgl());
                    yhDisaster.setYhUpdatetime(cityHouse.getFxpcUpdatetimeSjgl());
                    yhDisaster.setCreateUserId(PlatformSessionUtils.getUserId());
                    yhDisaster.setIsValid("1");
                    yhDisaster.setCreateTime(new Date());
                    yhDisasterEntities.add(yhDisaster);
                    // try {
                    //     yhDisasterBaseDao.save(yhDisaster);
                    // }catch (Exception e){
                    //     e.printStackTrace();
                    //     System.out.println("!!!!!!!!!!!!!!!!数据保存出错了"+ cityHouse.toString());
                    // }

                    count++;
                    if (count % 10000 == 0) {
                        System.out.println("当前解析了: " + count + " 条数据");
                    }
                }
                Long end = System.currentTimeMillis();
                System.out.println("解析" + yhDisasterEntities.size() + "条数据================总用时：" + (end - start));

                if (yhDisasterEntities.size() < commitSize) {
                    yhDisasterDao.batchSave(yhDisasterEntities);
                } else {
                    int size = yhDisasterEntities.size() / commitSize;
                    if (yhDisasterEntities.size() % commitSize != 0) {
                        size++;
                    }
                    for (int i = 0; i < size; i++) {
                        List<YhDisasterEntity> subList = null;
                        if ((i + 1) * commitSize > yhDisasterEntities.size()) {
                            subList = yhDisasterEntities.subList(i * commitSize, yhDisasterEntities.size());
                            System.out.println("===========当前提交数据位置:  " + yhDisasterEntities.size());
                        } else {
                            subList = yhDisasterEntities.subList(i * commitSize, (i + 1) * commitSize);
                            System.out.println("===========当前提交数据位置:  " + (i + 1) * commitSize);
                        }
                        yhDisasterDao.batchSave(subList);
                    }
                }
                System.out.println("=======入库总用时：" + (System.currentTimeMillis() - end));
                logger.info("城镇住宅插入条数:{},重复数据:{},插入时间:{}", yhDisasterEntities.size(), newData.size() - yhDisasterEntities.size(), LocalDate.now());
            }
            newData.clear();
        }
        return RestResultData.ok();
    }


    /**
     * risk_census_city_non_house 城镇非住宅
     */
    @Override
    public RestResultData shareDataCityNonHouse() {
        List<CityNonHouseEntity> newData = null;
        List<CityNonHouseEntity> updateData = null;
        // Arrays.asList("110000","130000","140000","150000","210000","220000","230000","310000",
        //                 "320000","350000","360000","370000","410000","420000","430000","440000","450000","460000","530000",
        //                 "540000","610000","650000","660000")
        for (String city1 : Arrays.asList("660000")) {
            if ("1".equals(begin)) {
                System.out.println("--------city:{}" + city1);
                newData = cityHouseNonBaseDao.findAllByLimit(city1);
            } else {
                // 日期格式yyyy-MM-dd ，为0则为当日，1则是全部数据,否则指定日期查询
                LocalDate beginDate = null;
                LocalDate endDate = null;
                if ("0".equals(begin)) {
                    beginDate = LocalDate.now();
                    endDate = LocalDate.now();
                } else {
                    // 根据时间段查询数据
                    beginDate = LocalDate.parse(begin, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    endDate = LocalDate.parse(end, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                }
                newData = cityHouseNonBaseDao.findAddByDate(beginDate, endDate);
                updateData = cityHouseNonBaseDao.findUpdateByDate(beginDate, endDate);
            }
            if (CollectionUtils.isEmpty(newData) && CollectionUtils.isEmpty(updateData)) {
                //throw new ParamServiceException(ServiceErrEnumInfo.NOTFOUND_RESULT_ERR, "没有数据更新");
                System.out.println(city1 + "城镇非住宅没有数据更新");
                continue;
            }
            //新增
            if (!CollectionUtils.isEmpty(newData)) {
                // List<YhDisastersEntity> yhDisasterEntities = new ArrayList<>();
                List<YhDisasterEntity> yhDisasterEntities = new ArrayList<>();
                int count = 0;
                Long start = System.currentTimeMillis();
                for (CityNonHouseEntity cityNonHouse : newData) {
                    // YhDisasterEntity yhDisaster = new YhDisaster37Entity11();
                    YhDisasterEntity yhDisaster = Entityutils.getEntity(cityNonHouse.getProvince());
                    yhDisaster.setId(UUID.randomUUID().toString().replace("-", ""));
                    yhDisaster.setYhCode(cityNonHouse.getBh());
                    yhDisaster.setYhUnit(cityNonHouse.getMc());
                    yhDisaster.setExtends4(cityNonHouse.getJzmc());
                    //建筑用途
                    String yhProjectName = null;
                    if (null == cityNonHouse.getFwyt()) {
                        yhProjectName = "其他";
                    } else {
                        switch (cityNonHouse.getFwyt()) {
                            case "1001":
                                yhProjectName = "中小学幼儿园教学楼宿舍楼等教育建筑";
                                break;
                            case "2":
                                yhProjectName = "其他学校建筑";
                                break;
                            case "1003":
                                yhProjectName = "医疗建筑";
                                break;
                            case "1004":
                                yhProjectName = "福利院";
                                break;
                            case "1005":
                                yhProjectName = "养老建筑";
                                break;
                            case "1006":
                                yhProjectName = "疾控、消防等救灾建筑";
                                break;
                            case "17":
                                yhProjectName = "纪念建筑";
                                break;
                            case "18":
                                yhProjectName = "宗教建筑";
                                break;
                            case "1009":
                                yhProjectName = "文化建筑";
                                break;
                            case "19":
                                yhProjectName = "综合建筑";
                                break;
                            case "1011":
                                yhProjectName = "商业建筑";
                                break;
                            case "1012":
                                yhProjectName = "体育建筑";
                                break;
                            case "1013":
                                yhProjectName = "通信电力交通邮电广播电视等基础设施建筑";
                                break;
                            case "14":
                                yhProjectName = "工业建筑";
                                break;
                            case "15":
                                yhProjectName = "办公建筑";
                                break;
                            case "16":
                                yhProjectName = "仓储建筑";
                                break;
                            case "99999":
                                yhProjectName = "其他";
                                break;
                            default:
                                yhProjectName = "其他";
                        }
                    }
                    yhDisaster.setYhProjectName(yhProjectName);
                    yhDisaster.setYhProjectType(getProjectType(null, yhProjectName));
                    //验重
                    // boolean isRRepeat = false;
                    // for (Object[] yhCodeAndYhProjectType : yhCodeAndYhProjectTypes) {
                    //     if (yhCodeAndYhProjectType[0].toString().equals(cityNonHouse.getBh()) &&
                    //             yhCodeAndYhProjectType[1].toString().equals(yhDisaster.getYhProjectType())) {
                    //         isRRepeat = true;
                    //         //logger.info("城镇非住宅数据重复，重复编码:{}", cityNonHouse.getBh());
                    //         break;
                    //     }
                    // }
                    // if (isRRepeat) continue;
                    yhDisaster.setProvince(divisionInfoMap.get(cityNonHouse.getProvince()).toString());
                    String city = cityNonHouse.getCity();
                    if (city.equals("110100") || city.equals("120100") || city.equals("310100") || city.equals("500100")) {
                        city = city.substring(0, 2) + "0000";
                    }
                    yhDisaster.setCity(divisionInfoMap.get(city).toString());
                    yhDisaster.setArea(divisionInfoMap.get(cityNonHouse.getDistrict()).toString());
                    yhDisaster.setDetailedAddress(cityNonHouse.getAddress());
                    String[] lonLat = {"0", "0"};
                    if (Objects.isNull(cityNonHouse.getShape())) {
                    } else {
                        String str = cityNonHouse.getShape().toString();
                        lonLat = getLonLat(str);//纬度
                        //yhDisaster.setSpaceData(str.split(";")[1]);//空间数据
                        yhDisaster.setSpaceData(str);//空间数据
                        yhDisaster.setLatitude(lonLat[1]);
                        yhDisaster.setLongitude(lonLat[0]);
                    }
                    yhDisaster.setYhConstructionPrice("");//造价
                    if (Objects.isNull(cityNonHouse.getDcmj())) {
                        yhDisaster.setYhConstructionScale("0");
                    } else {
                        yhDisaster.setYhConstructionScale(cityNonHouse.getDcmj().toString());//建设规模
                    }
//                yhDisaster.setYhProjectTask(CommonConstant.TYPE_CITY_NO_HOUSE);//工程任务-建筑名称
                    String buildTime = cityNonHouse.getBuildTime();//建造年代
                    yhDisaster.setBuildingTimeDetails(buildTime);
                    if (StringUtils.isEmpty(buildTime)) {
                        buildTime = CommonConstant.BUILDTIME_NO;
                        yhDisaster.setBuildingTimeDetails("0");
                    } else {
                        Integer integer = 0;
                        if (buildTime.length() >= 4) {
                            integer = Integer.valueOf(buildTime.substring(0, 4));
                        } else {
                            yhDisaster.setYhBuildingTime(CommonConstant.BUILDTIME_NO);
                        }
                        if (integer < 1989) {
                            buildTime = CommonConstant.BUILDTIME_1989;
                        } else if (integer >= 1990 && integer < 2000) {
                            buildTime = CommonConstant.BUILDTIME_1990;
                        } else if (integer >= 2000 && integer <= 2011) {
                            buildTime = CommonConstant.BUILDTIME_2000;
                        } else if (integer > 2011) {
                            buildTime = CommonConstant.BUILDTIME_2011;
                        } else {
                            buildTime = CommonConstant.BUILDTIME_NO;
                        }
                    }
                    yhDisaster.setYhBuildingTime(buildTime);
                    //设防类别
                    String yhEarthFortification = null;
                    // if (yhDisaster.getYhProjectType().equals("其他")) {
                    //     yhEarthFortification = CommonConstant.EARTHFORTIFICATION_III;
                    // } else {
                    //     yhEarthFortification = CommonConstant.EARTHFORTIFICATION_II;
                    // }
                    if (null == cityNonHouse.getMqsflb()) {
                        if (yhDisaster.getYhProjectType().equals("其他")) {
                            yhEarthFortification = CommonConstant.EARTHFORTIFICATION_III;
                        } else {
                            yhEarthFortification = CommonConstant.EARTHFORTIFICATION_II;
                        }
                    } else {
                        switch (cityNonHouse.getMqsflb()) {
                            case "1":
                                yhEarthFortification = CommonConstant.EARTHFORTIFICATION_I;
                                break;
                            case "2":
                                yhEarthFortification = CommonConstant.EARTHFORTIFICATION_II;
                                break;
                            case "3":
                                yhEarthFortification = CommonConstant.EARTHFORTIFICATION_III;
                                break;
                            case "4":
                                yhEarthFortification = CommonConstant.EARTHFORTIFICATION_IV;
                                break;
                            default:
                                yhEarthFortification = CommonConstant.EARTHFORTIFICATION_II;
                        }
                    }
                    yhDisaster.setYhEarthFortification(yhEarthFortification);//抗震设防类别
                    //原设防烈度
                    String yearthIntensity = null;
                    if (Objects.isNull(cityNonHouse.getJzsfld())) {
                        yearthIntensity = CommonConstant.SFLD_N0;
                    } else {
                        switch (cityNonHouse.getJzsfld().intValue()) {
                            case 1:
                                yearthIntensity = CommonConstant.SFLD_N0;
                                break;
                            case 2:
                                yearthIntensity = CommonConstant.SFLD_6;
                                break;
                            case 3:
                                yearthIntensity = CommonConstant.SFLD_70;
                                break;
                            case 4:
                                yearthIntensity = CommonConstant.SFLD_75;
                                break;
                            case 5:
                                yearthIntensity = CommonConstant.SFLD_82;
                                break;
                            case 6:
                                yearthIntensity = CommonConstant.SFLD_83;
                                break;
                            case 7:
                                yearthIntensity = CommonConstant.SFLD_94;
                                break;
                            default:
                                yearthIntensity = CommonConstant.SFLD_N0;
                        }
                    }

                    yhDisaster.setYhEarthIntensity(yearthIntensity);
                    //现设防烈度
                    String nowEarthQh = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    String extends5 = null;
                    if (!Objects.isNull(cityNonHouse.getMqsfld())) {
                        switch (cityNonHouse.getMqsfld().intValue()) {
                            case 1:
                                extends5 = CommonConstant.SFLD_N0;
                                break;
                            case 2:
                                extends5 = CommonConstant.SFLD_6;
                                break;
                            case 3:
                                extends5 = CommonConstant.SFLD_70;
                                break;
                            case 4:
                                extends5 = CommonConstant.SFLD_75;
                                break;
                            case 5:
                                extends5 = CommonConstant.SFLD_82;
                                break;
                            case 6:
                                extends5 = CommonConstant.SFLD_83;
                                break;
                            case 7:
                                extends5 = CommonConstant.SFLD_94;
                                break;
                            default:
                                extends5 = CommonConstant.SFLD_N0;
                        }
                    }
                    // if (Objects.isNull(cityNonHouse.getMqsfld())) {
                    //     //nowEarthQh = CommonConstant.SFLD_70;
                    //     nowEarthQh = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    // } else {
                    //     switch (cityNonHouse.getMqsfld().intValue()) {
                    //         case 1:
                    //             nowEarthQh = CommonConstant.SFLD_6;
                    //             break;
                    //         case 2:
                    //             nowEarthQh = CommonConstant.SFLD_70;
                    //             break;
                    //         case 3:
                    //             nowEarthQh = CommonConstant.SFLD_75;
                    //             break;
                    //         case 4:
                    //             nowEarthQh = CommonConstant.SFLD_82;
                    //             break;
                    //         case 5:
                    //             nowEarthQh = CommonConstant.SFLD_83;
                    //             break;
                    //         case 6:
                    //             nowEarthQh = CommonConstant.SFLD_94;
                    //             break;
                    //         default:
                    //             //nowEarthQh = CommonConstant.SFLD_6;
                    //             nowEarthQh = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    //     }
                    // }

                    yhDisaster.setYhNowEarthQh(nowEarthQh);//现抗震设防区划
                    yhDisaster.setExtends5(extends5);
                    yhDisaster.setYhFieldType(getSiteTypeFromLonLat(lonLat[0], lonLat[1], yhDisaster.getProvince()) + "类场地");//场地类别默认二类
                    //现存灾害
                    if ("1".equals(cityNonHouse.getYwlfbxqx())) {//有
                        if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SERIOUS);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_BIG);
                        }
                    } else {
                        if (CommonConstant.BUILDTIME_2011.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_NO);
                        } else if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_COMMON);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SLIGHT);
                        }
                    }
                    yhDisaster.setExtends1(CommonConstant.TYPE_CITY_NO_HOUSE_CH);
                    yhDisaster.setExtends3(cityNonHouse.getFxpcDataidSjgl());
                    yhDisaster.setQualityResult("1");
                    yhDisaster.setReviewStatus("1");
                    yhDisaster.setYhCreatetime(cityNonHouse.getFxpcCreatetimeSjgl());
                    yhDisaster.setYhUpdatetime(cityNonHouse.getFxpcUpdatetimeSjgl());
                    yhDisaster.setCreateUserId(PlatformSessionUtils.getUserId());
                    yhDisaster.setIsValid("1");
                    yhDisaster.setCreateTime(new Date());
                    yhDisasterEntities.add(yhDisaster);
                    count++;
                    if (count % 10000 == 0) {
                        System.out.println("当前解析了: " + count + " 条数据");
                    }
                }
                Long end = System.currentTimeMillis();
                System.out.println("解析" + yhDisasterEntities.size() + "条数据================总用时：" + (end - start));

                if (yhDisasterEntities.size() < commitSize) {
                    yhDisasterDao.batchSave(yhDisasterEntities);
                } else {
                    int size = yhDisasterEntities.size() / commitSize;
                    if (yhDisasterEntities.size() % commitSize != 0) {
                        size++;
                    }
                    for (int i = 0; i < size; i++) {
                        List<YhDisasterEntity> subList = null;
                        if ((i + 1) * commitSize > yhDisasterEntities.size()) {
                            subList = yhDisasterEntities.subList(i * commitSize, yhDisasterEntities.size());
                            System.out.println("===========当前提交数据位置:  " + yhDisasterEntities.size());
                        } else {
                            subList = yhDisasterEntities.subList(i * commitSize, (i + 1) * commitSize);
                            System.out.println("===========当前提交数据位置:  " + (i + 1) * commitSize);
                        }
                        yhDisasterDao.batchSave(subList);
                    }
                }
                System.out.println("=======入库总用时：" + (System.currentTimeMillis() - end));
                logger.info("城镇非住宅插入条数:{},重复数据:{},插入时间:{}", yhDisasterEntities.size(), newData.size() - yhDisasterEntities.size(), LocalDate.now());
            }
            newData.clear();
        }
        return RestResultData.ok();
    }

    /**
     * risk_census_country_dl_house农村独立住宅
     */
    @Override
    public RestResultData shareDataCountryDlHouse() {
        List<CountryDlHouseEntity> newData = null;
        List<CountryDlHouseEntity> updateData = null;
        // Arrays.asList("330000", "340000", "500000", "510000","520000","620000","630000","640000")
        //"130102","130104","130105","130107","130108","130109","130110","130111",
        //         "130121","130123","130125","130126","130127","130128","130129","130130","130131","130132","130133",
        //         "130171","130181","130183","130184","310116","310117","371102","371103","371121","371122","420902",
        //         "420921","420922","420923","420981","420982","420984","540302","540321","540322","540323","540324",
        //         "540325","540326","540327","540328","540329","540330","650103","650104","650105","650106","650107",
        //         "650109","650121",
        // List<String> lists=Arrays.asList("661201","661202","661203","661204","661205","661206","661207");
        // List<String> lists=Arrays.asList("110112","140302","140303","140311","140321","140322","211002","211003",
        //             "211004","211005","211011","211021","211081","220302","220303","220322","220323","220382","350203",
        //             "350205","350206","350211","350212","350213","460400","532301","532322","532323","532324","532325",
        //             "532326","532327","532328","532329","532331","610902","610921","610922","610923","610924","610925",
        //             "610926","610927","610928","610929");
        // List<String> lists=Arrays.asList("230302","230303","230304","230305","230306","230307","230321",
        //             "230381","230382","320105","320106","320111","320113","320114","320115","320116","320117","320118",
        //             "320171","450102","450103","450105","450107","450108","450109","450110","450123","450124","450125",
        //             "450126","450127");
        List<String> lists = Arrays.asList("360802", "360803", "360821", "360822", "360823", "360824", "360825", "360826",
                "360827", "360828", "360829", "360830", "360881", "410302", "410303", "410304", "410305", "410308", "410311",
                "410323", "410324", "410325", "410326", "410327", "410328", "410329", "410371", "410381", "430902", "430903",
                "430921", "430922", "430923", "430981");

        for (String city1 : lists) {
            if ("1".equals(begin)) {
                System.out.println("--------city:{}" + city1);
                //newData = countryDlHouseBaseDao.findAll();
                newData = countryDlHouseBaseDao.findDlHouseAll(city1);
            } else {
                // 日期格式yyyy-MM-dd ，为0则为当日，1则是全部数据,否则指定日期查询
                LocalDate beginDate = null;
                LocalDate endDate = null;
                if ("0".equals(begin)) {
                    beginDate = LocalDate.now();
                    endDate = LocalDate.now();
                } else {
                    // 根据时间段查询数据
                    beginDate = LocalDate.parse(begin, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    endDate = LocalDate.parse(end, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                }
                newData = countryDlHouseBaseDao.findAddByDate(beginDate, endDate);
                updateData = countryDlHouseBaseDao.findUpdateByDate(beginDate, endDate);
            }
            if (CollectionUtils.isEmpty(newData) && CollectionUtils.isEmpty(updateData)) {
                System.out.println(city1 + ",农村独立住宅没有数据更新");
                continue;
            }
            //新增
            if (!CollectionUtils.isEmpty(newData)) {
                // List<YhDisastersEntity> yhDisasterEntities = new ArrayList<>();
                List<YhDisasterEntity> yhDisasterEntities = new ArrayList<>();
                int count = 0;
                Long start = System.currentTimeMillis();
                for (CountryDlHouseEntity countryDlHouse : newData) {
                    YhDisasterEntity yhDisaster = Entityutils.getEntity(countryDlHouse.getProvince());
                    yhDisaster.setId(UUID.randomUUID().toString().replace("-", ""));
                    yhDisaster.setYhCode(countryDlHouse.getBh());
                    yhDisaster.setYhUnit("农村独立住宅小区单位");
                    yhDisaster.setYhProjectType(CommonConstant.PROJECT_TYPE_HOUSE);
                    //验重
                    // boolean isRRepeat = false;
                    // for (Object[] yhCodeAndYhProjectType : yhCodeAndYhProjectTypes) {
                    //     if (yhCodeAndYhProjectType[0].toString().equals(countryDlHouse.getBh()) &&
                    //             yhCodeAndYhProjectType[1].toString().equals(CommonConstant.PROJECT_TYPE_HOUSE)) {
                    //         isRRepeat = true;
                    //         //logger.info("农村独立住宅数据重复，重复编码:{}", countryDlHouse.getBh());
                    //         break;
                    //     }
                    // }
                    // if (isRRepeat) continue;
                    // yhDisaster.setProvince(divisionInfoMap.get(countryDlHouse.getFxpcXzqhbmaSjgl()).toString());
                    // String city = countryDlHouse.getFxpcXzqhbmbSjgl();
                    // if (city.equals("110100") || city.equals("120100") || city.equals("310100") || city.equals("500100")) {
                    //     city = city.substring(0, 2) + "0000";
                    // }
                    // yhDisaster.setCity(divisionInfoMap.get(city).toString());
                    // yhDisaster.setArea(divisionInfoMap.get(countryDlHouse.getFxpcXzqhbmcSjgl()).toString());
                    yhDisaster.setProvince(divisionInfoMap.get(countryDlHouse.getProvince()).toString());
                    String city = countryDlHouse.getCity();
                    if (city.equals("110100") || city.equals("120100") || city.equals("310100") || city.equals("500100")) {
                        city = city.substring(0, 2) + "0000";
                    }
                    yhDisaster.setCity(divisionInfoMap.get(city).toString());
                    yhDisaster.setArea(divisionInfoMap.get(countryDlHouse.getDistrict()).toString());
                    yhDisaster.setDetailedAddress(countryDlHouse.getAddress());
                    String[] lonLat = {"0", "0"};
                    if (Objects.isNull(countryDlHouse.getShape())) {
                        //throw new ParamServiceException(ServiceErrEnumInfo.NOTFOUND_RESULT_ERR, "空间数据为空");
                    } else {
                        String str = countryDlHouse.getShape().toString();
                        lonLat = getLonLat(str);//纬度
                        //yhDisaster.setSpaceData(str.split(";")[1]);//空间数据
                        yhDisaster.setSpaceData(str);//空间数据
                        yhDisaster.setLatitude(lonLat[1]);
                        yhDisaster.setLongitude(lonLat[0]);
                    }
                    yhDisaster.setYhConstructionPrice("");//造价
                    if (Objects.isNull(countryDlHouse.getDcmj())) {
                        yhDisaster.setYhConstructionScale("0");
                    } else {
                        yhDisaster.setYhConstructionScale(countryDlHouse.getDcmj().toString());//建设规模
                    }
                    //yhDisaster.setYhProjectTask(CommonConstant.TYPE_COUNTRY_DL_HOUSE);//工程任务-主键类型
                    String buildTime = countryDlHouse.getJznd();//建造年代
                    yhDisaster.setBuildingTimeDetails(buildTime);
                    if (StringUtils.isEmpty(buildTime)) {
                        buildTime = CommonConstant.BUILDTIME_NO;
                        yhDisaster.setBuildingTimeDetails("0");
                    } else {
                        switch (buildTime) {
                            case "1":
                            case "2":
                                buildTime = CommonConstant.BUILDTIME_1989;
                                break;
                            case "3":
                                buildTime = CommonConstant.BUILDTIME_1990;
                                break;
                            case "4":
                                buildTime = CommonConstant.BUILDTIME_2000;
                                break;
                            case "5":
                            case "6":
                                buildTime = CommonConstant.BUILDTIME_2011;
                                break;
                            default:
                                buildTime = CommonConstant.BUILDTIME_NO;
                                break;
                        }
                    }
                    yhDisaster.setYhBuildingTime(buildTime);
                    yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_III);//抗震设防类别
                    //原设防烈度-抗震设防情况
                    String yearthIntensity = null;
                    if (countryDlHouse.getKzsfqk() == null) {
                        yearthIntensity = CommonConstant.SFLD_N0;
                    } else {
                        switch (countryDlHouse.getKzsfqk()) {
                            // case "1":
                            //     yearthIntensity = CommonConstant.SFLD_6;
                            //     break;
                            // case "2":
                            //     yearthIntensity = CommonConstant.SFLD_70;
                            //     break;
                            // case "3":
                            //     yearthIntensity = CommonConstant.SFLD_82;
                            //     break;
                            // case "4":
                            //     yearthIntensity = CommonConstant.SFLD_94;
                            //     break;
                            case "2":
                                yearthIntensity = CommonConstant.SFLD_6;
                                break;
                            case "3":
                                yearthIntensity = CommonConstant.SFLD_70;
                                break;
                            case "5":
                                yearthIntensity = CommonConstant.SFLD_82;
                                break;
                            case "7":
                                yearthIntensity = CommonConstant.SFLD_94;
                                break;
                            default:
                                yearthIntensity = CommonConstant.SFLD_N0;
                        }
                    }
                    yhDisaster.setYhEarthIntensity(yearthIntensity);
                    //现抗震设防区划
                    String nowdata = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    yhDisaster.setYhNowEarthQh(nowdata);
                    yhDisaster.setYhFieldType(getSiteTypeFromLonLat(lonLat[0], lonLat[1], yhDisaster.getProvince()) + "类场地");//场地类别默认二类
                    //现存灾害
                    if ("1".equals(countryDlHouse.getYwlfbxqx())) {//有
                        if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SERIOUS);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_BIG);
                        }
                    } else {
                        if (CommonConstant.BUILDTIME_2011.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_NO);
                        } else if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_COMMON);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SLIGHT);
                        }
                    }
                    yhDisaster.setExtends1(CommonConstant.TYPE_COUNTRY_DL_HOUSE_CH);
                    yhDisaster.setExtends3(countryDlHouse.getFxpcDataidSjgl());
                    yhDisaster.setQualityResult("1");
                    yhDisaster.setReviewStatus("1");
                    yhDisaster.setYhCreatetime(countryDlHouse.getFxpcCreatetimeSjgl());
                    yhDisaster.setYhUpdatetime(countryDlHouse.getFxpcUpdatetimeSjgl());
                    yhDisaster.setCreateUserId(PlatformSessionUtils.getUserId());
                    yhDisaster.setIsValid("1");
                    yhDisaster.setCreateTime(new Date());
                    yhDisasterEntities.add(yhDisaster);
                    count++;
                    if (count % 10000 == 0) {
                        System.out.println("当前解析了: " + count + " 条数据");
                    }
                }
                Long end = System.currentTimeMillis();
                System.out.println("解析" + yhDisasterEntities.size() + "条数据================总用时：" + (end - start));
                if (yhDisasterEntities.size() < commitSize) {
                    yhDisasterDao.batchSave(yhDisasterEntities);
                } else {
                    int size = yhDisasterEntities.size() / commitSize;
                    if (yhDisasterEntities.size() % commitSize != 0) {
                        size++;
                    }
                    for (int i = 0; i < size; i++) {
                        List<YhDisasterEntity> subList = null;
                        if ((i + 1) * commitSize > yhDisasterEntities.size()) {
                            subList = yhDisasterEntities.subList(i * commitSize, yhDisasterEntities.size());
                            System.out.println("===========当前提交数据位置:  " + yhDisasterEntities.size());
                        } else {
                            subList = yhDisasterEntities.subList(i * commitSize, (i + 1) * commitSize);
                            System.out.println("===========当前提交数据位置:  " + (i + 1) * commitSize);
                        }
                        yhDisasterDao.batchSave(subList);
                    }
                }
                System.out.println("=======入库总用时：" + (System.currentTimeMillis() - end));
                logger.info("农村独立住宅插入条数:{},重复数据:{},插入时间:{}", yhDisasterEntities.size(), newData.size() - yhDisasterEntities.size(), LocalDate.now());
            }
            newData.clear();
        }
        return RestResultData.ok();
    }

    /**
     * 农村集合住宅
     */
    @Override
    public RestResultData shareDataCountryJhHouse() {
        List<CountryJhHouseEntity> newData = null;
        List<CountryJhHouseEntity> updateData = null;
        // Arrays.asList("110000","130000","140000","150000","210000","220000","230000","310000",
        //                 "320000","350000","360000","370000","410000","420000","430000"/*,"440000"*/,"450000","460000","530000",
        //                 "540000","610000","650000","660000")
        for (String city1 : Arrays.asList("110000", "130000", "140000", "210000", "220000", "230000", "310000",
                "320000", "350000", "360000", "370000", "410000", "420000", "430000"/*,"440000"*/, "450000", "460000", "530000",
                "540000", "610000", "650000")) {
            if ("1".equals(begin)) {
                System.out.println("=============city1:" + city1);
                newData = countryJhHouseBaseDao.findJhHouseAll(city1);
            } else {
                // 日期格式yyyy-MM-dd ，为0则为当日，1则是全部数据,否则指定日期查询
                LocalDate beginDate = null;
                LocalDate endDate = null;
                if ("0".equals(begin)) {
                    beginDate = LocalDate.now();
                    endDate = LocalDate.now();
                } else {
                    // 根据时间段查询数据
                    beginDate = LocalDate.parse(begin, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    endDate = LocalDate.parse(end, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                }
                newData = countryJhHouseBaseDao.findAddByDate(beginDate, endDate);
                updateData = countryJhHouseBaseDao.findUpdateByDate(beginDate, endDate);
            }
            if (CollectionUtils.isEmpty(newData) && CollectionUtils.isEmpty(updateData)) {
                System.out.println("农村集合住宅没有数据更新");
                continue;
            }
            //新增
            if (!CollectionUtils.isEmpty(newData)) {
                // List<YhDisastersEntity> yhDisasterEntities = new ArrayList<>();
                List<YhDisasterEntity> yhDisasterEntities = new ArrayList<>();
                Long start = System.currentTimeMillis();
                int count = 0;
                for (CountryJhHouseEntity countryHouse : newData) {
                    // YhDisasterEntity yhDisaster = new YhDisaster37Entity12();
                    YhDisasterEntity yhDisaster = Entityutils.getEntity(countryHouse.getProvince());
                    yhDisaster.setId(UUID.randomUUID().toString().replace("-", ""));
                    yhDisaster.setYhCode(countryHouse.getBh());
                    yhDisaster.setYhUnit(countryHouse.getAddress());
                    yhDisaster.setExtends4(countryHouse.getJzmc());
                    yhDisaster.setYhProjectType(CommonConstant.PROJECT_TYPE_HOUSE);
                    // 验重
                    // boolean isRRepeat = false;
                    // List<Object[]> objects = yhCodeAndYhProjectTypesAll.get(countryHouse.getProvince());
                    // if (objects.size()!=0) {
                    //     for (Object[] yhCodeAndYhProjectType : objects) {
                    //         if (yhCodeAndYhProjectType[0].toString().equals(countryHouse.getBh()) &&
                    //                 yhCodeAndYhProjectType[1].toString().equals(CommonConstant.PROJECT_TYPE_HOUSE)) {
                    //             isRRepeat = true;
                    //             //logger.info("农村集合住宅数据重复，重复编码:{}", countryHouse.getBh());
                    //             break;
                    //         }
                    //     }
                    // }
                    // if (isRRepeat) continue;
                    yhDisaster.setProvince(divisionInfoMap.get(countryHouse.getProvince()).toString());
                    String city = countryHouse.getCity();
                    if (city.equals("110100") || city.equals("120100") || city.equals("310100") || city.equals("500100")) {
                        city = city.substring(0, 2) + "0000";
                    }
                    yhDisaster.setCity(divisionInfoMap.get(city).toString());
                    yhDisaster.setArea(divisionInfoMap.get(countryHouse.getDistrict()).toString());
                    yhDisaster.setDetailedAddress(countryHouse.getAddress());
                    String[] lonLat = {"0", "0"};
                    if (Objects.isNull(countryHouse.getShape())) {
                        //throw new ParamServiceException(ServiceErrEnumInfo.NOTFOUND_RESULT_ERR, "农村独立住宅没有数据更新");
                    } else {
                        String str = countryHouse.getShape().toString();
                        lonLat = getLonLat(str);//纬度
                        //yhDisaster.setSpaceData(str.split(";")[1]);//空间数据
                        yhDisaster.setSpaceData(str);//空间数据
                        yhDisaster.setLatitude(lonLat[1]);
                        yhDisaster.setLongitude(lonLat[0]);
                    }
                    yhDisaster.setYhConstructionPrice("");//造价
                    if (Objects.isNull(countryHouse.getDcmj())) {
                        yhDisaster.setYhConstructionScale("0");
                    } else {
                        yhDisaster.setYhConstructionScale(countryHouse.getDcmj().toString());//建设规模
                    }
//                yhDisaster.setYhProjectTask(CommonConstant.TYPE_COUNTRY_JH_HOUSE);
                    String buildTime = countryHouse.getJznd();//建造年代
                    yhDisaster.setBuildingTimeDetails(buildTime);
                    if (StringUtils.isEmpty(buildTime)) {
                        buildTime = CommonConstant.BUILDTIME_NO;
                        yhDisaster.setBuildingTimeDetails("0");
                    } else {
                        switch (buildTime) {
                            case "1":
                            case "2":
                                buildTime = CommonConstant.BUILDTIME_1989;
                                break;
                            case "3":
                                buildTime = CommonConstant.BUILDTIME_1990;
                                break;
                            case "4":
                                buildTime = CommonConstant.BUILDTIME_2000;
                                break;
                            case "5":
                            case "6":
                                buildTime = CommonConstant.BUILDTIME_2011;
                                break;
                            default:
                                buildTime = CommonConstant.BUILDTIME_NO;
                                break;
                        }
                    }
                    yhDisaster.setYhBuildingTime(buildTime);
                    yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_III);//抗震设防类别
                    //原设防烈度-抗震设防情况
                    //原设防烈度
                    String yearthIntensity = null;
                    if (countryHouse.getKzsfqk() == null) {
                        yearthIntensity = CommonConstant.SFLD_N0;
                    } else {
                        switch (countryHouse.getKzsfqk()) {
                            // case "1":
                            //     yearthIntensity = CommonConstant.SFLD_6;
                            //     break;
                            // case "2":
                            //     yearthIntensity = CommonConstant.SFLD_70;
                            //     break;
                            // case "3":
                            //     yearthIntensity = CommonConstant.SFLD_82;
                            //     break;
                            // case "4":
                            //     yearthIntensity = CommonConstant.SFLD_94;
                            //     break;
                            case "2":
                                yearthIntensity = CommonConstant.SFLD_6;
                                break;
                            case "3":
                                yearthIntensity = CommonConstant.SFLD_70;
                                break;
                            case "5":
                                yearthIntensity = CommonConstant.SFLD_82;
                                break;
                            case "7":
                                yearthIntensity = CommonConstant.SFLD_94;
                                break;
                            default:
                                yearthIntensity = CommonConstant.SFLD_N0;
                        }
                    }
                    yhDisaster.setYhEarthIntensity(yearthIntensity);
                    //现抗震设防区划
                    String nowdata = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    yhDisaster.setYhNowEarthQh(nowdata);
                    yhDisaster.setYhFieldType(getSiteTypeFromLonLat(lonLat[0], lonLat[1], yhDisaster.getProvince()) + "类场地");//场地类别默认二类(CommonConstant.FIELDTYPE_II);
                    //现存灾害
                    if ("1".equals(countryHouse.getYwlfbxqx())) {//有
                        if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SERIOUS);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_BIG);
                        }
                    } else {
                        if (CommonConstant.BUILDTIME_2011.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_NO);
                        } else if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_COMMON);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SLIGHT);
                        }
                    }
                    yhDisaster.setExtends1(CommonConstant.TYPE_COUNTRY_JH_HOUSE_CH);
                    yhDisaster.setExtends3(countryHouse.getFxpcDataidSjgl());
                    yhDisaster.setQualityResult("1");
                    yhDisaster.setReviewStatus("1");
                    yhDisaster.setYhCreatetime(countryHouse.getFxpcCreatetimeSjgl());
                    yhDisaster.setYhUpdatetime(countryHouse.getFxpcUpdatetimeSjgl());
                    yhDisaster.setCreateUserId(PlatformSessionUtils.getUserId());
                    yhDisaster.setIsValid("1");
                    yhDisaster.setCreateTime(new Date());
                    yhDisasterEntities.add(yhDisaster);
                    count++;
                    if (count % 10000 == 0) {
                        System.out.println("当前解析了: " + count + " 条数据");
                    }
                }
                Long end = System.currentTimeMillis();
                System.out.println("解析" + yhDisasterEntities.size() + "条数据================总用时：" + (end - start));
                if (yhDisasterEntities.size() < commitSize) {
                    yhDisasterDao.batchSave(yhDisasterEntities);
                } else {
                    int size = yhDisasterEntities.size() / commitSize;
                    if (yhDisasterEntities.size() % commitSize != 0) {
                        size++;
                    }
                    for (int i = 0; i < size; i++) {
                        List<YhDisasterEntity> subList = null;
                        if ((i + 1) * commitSize > yhDisasterEntities.size()) {
                            subList = yhDisasterEntities.subList(i * commitSize, yhDisasterEntities.size());
                            System.out.println("===========当前提交数据位置:  " + yhDisasterEntities.size());
                        } else {
                            subList = yhDisasterEntities.subList(i * commitSize, (i + 1) * commitSize);
                            System.out.println("===========当前提交数据位置:  " + (i + 1) * commitSize);
                        }
                        yhDisasterDao.batchSave(subList);
                    }
                }
                System.out.println("=======入库总用时：" + (System.currentTimeMillis() - end));
                logger.info("农村集合住宅插入条数:{},重复数据:{},插入时间:{}", yhDisasterEntities.size(), newData.size() - yhDisasterEntities.size(), LocalDate.now());
            }
            newData.clear();
        }

        return RestResultData.ok();
    }


    /**
     * risk_census_city_non_house 农村非住宅
     */
    @Override
    public RestResultData shareDataCountryNonHouse() {
        List<CountryNonHouseEntity> newData = null;
        List<CountryNonHouseEntity> updateData = null;
        // Arrays.asList("110000","130000","140000","150000","210000","220000","230000","310000",
        //                 "320000","350000","360000","370000","410000","420000","430000"/*,"440000"*/,"450000","460000","530000",
        //                 "540000","610000","650000","660000")
        for (String city1 : Arrays.asList("110000", "130000", "140000")) {
            if ("1".equals(begin)) {
                System.out.println("=============city1:" + city1);
                newData = countryNoHouseBaseDao.findNoHouseAll(city1);
            } else {
                // 日期格式yyyy-MM-dd ，为0则为当日，1则是全部数据,否则指定日期查询
                LocalDate beginDate = null;
                LocalDate endDate = null;
                if ("0".equals(begin)) {
                    beginDate = LocalDate.now();
                    endDate = LocalDate.now();
                } else {
                    // 根据时间段查询数据
                    beginDate = LocalDate.parse(begin, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    endDate = LocalDate.parse(end, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                }
                newData = countryNoHouseBaseDao.findAddByDate(beginDate, endDate);
                updateData = countryNoHouseBaseDao.findUpdateByDate(beginDate, endDate);
            }
            if (CollectionUtils.isEmpty(newData) && CollectionUtils.isEmpty(updateData)) {
                System.out.println(city1 + "农村非住宅没有数据更新");
                continue;
            }
            //新增
            if (!CollectionUtils.isEmpty(newData)) {
                // List<YhDisastersEntity> yhDisasterEntities = new ArrayList<>();
                List<YhDisasterEntity> yhDisasterEntities = new ArrayList<>();
                int count = 0;
                Long start = System.currentTimeMillis();
                for (CountryNonHouseEntity countryNoHouse : newData) {
                    // YhDisasterEntity yhDisaster = new YhDisaster37Entity12();
                    YhDisasterEntity yhDisaster = Entityutils.getEntity(countryNoHouse.getProvince());
                    yhDisaster.setId(UUID.randomUUID().toString().replace("-", ""));
                    yhDisaster.setYhCode(countryNoHouse.getBh());
                    yhDisaster.setYhUnit("农村非住宅单位");
                    yhDisaster.setExtends4(countryNoHouse.getJzmc());
                    //建筑用途
                    String yhProjectName = null;
                    if (StringUtils.isEmpty(countryNoHouse.getJzyt())) {
                        yhProjectName = "其他";
                    } else {
                        switch (countryNoHouse.getJzyt()) {
                            case "1":
                                yhProjectName = "教育设施";
                                break;
                            case "2":
                                yhProjectName = "医疗卫生";
                                break;
                            case "3":
                                yhProjectName = "行政办公";
                                break;
                            case "4":
                                yhProjectName = "文化设施";
                                break;
                            case "5":
                                yhProjectName = "养老服务";
                                break;
                            case "6":
                                yhProjectName = "批发零售";
                                break;
                            case "7":
                                yhProjectName = "餐饮服务";
                                break;
                            case "8":
                                yhProjectName = "住宿宾馆";
                                break;
                            case "9":
                                yhProjectName = "休闲娱乐";
                                break;
                            case "10":
                                yhProjectName = "宗教场所";
                                break;
                            case "11":
                                yhProjectName = "农贸市场";
                                break;
                            case "12":
                                yhProjectName = "生产加工";
                                break;
                            case "13":
                                yhProjectName = "仓储物流";
                                break;
                            default:
                                yhProjectName = "其他";
                        }
                    }
                    yhDisaster.setYhProjectName(yhProjectName);
                    yhDisaster.setYhProjectType(getProjectType(null, yhProjectName));
                    //List<YhDisastersEntity> disaster = yhDisasterBaseDao.findByYhCodeAndIsValidAndYhProjectType(countryNoHouse.getBh(), "1", yhDisaster.getYhProjectType());
                    //验重
                    // boolean isRepeat = false;
                    // for (Object[] yhCodeAndYhProjectType : yhCodeAndYhProjectTypes) {
                    //     if (yhCodeAndYhProjectType[0].toString().equals(countryNoHouse.getBh()) &&
                    //             yhCodeAndYhProjectType[1].toString().equals(yhDisaster.getYhProjectType())) {
                    //         isRepeat = true;
                    //         //logger.info("农村非住宅数据重复，重复编码:{}", countryNoHouse.getBh());
                    //         break;
                    //     }
                    // }
                    // if (isRepeat) continue;
                    Object provinceCode = divisionInfoMap.get(countryNoHouse.getProvince());
                    if (null == provinceCode) {
                        //yhDisaster.setProvince(countryNoHouse.getProvince());
                        continue;
                    } else {
                        yhDisaster.setProvince(provinceCode.toString());
                    }
                    String city = countryNoHouse.getCity();
                    if (city.equals("110100") || city.equals("120100") || city.equals("310100") || city.equals("500100")) {
                        city = city.substring(0, 2) + "0000";
                    }
                    yhDisaster.setCity(divisionInfoMap.get(city).toString());
                    yhDisaster.setArea(divisionInfoMap.get(countryNoHouse.getDistrict()).toString());
                    yhDisaster.setDetailedAddress(countryNoHouse.getAddress());
                    String[] lonLat = {"0", "0"};
                    if (Objects.isNull(countryNoHouse.getShape())) {
                        //throw new ParamServiceException(ServiceErrEnumInfo.NOTFOUND_RESULT_ERR, "农村独立住宅没有数据更新");
                    } else {
                        String str = countryNoHouse.getShape().toString();
                        lonLat = getLonLat(str);//纬度
                        //yhDisaster.setSpaceData(str.split(";")[1]);//空间数据
                        yhDisaster.setSpaceData(str);//空间数据
                        yhDisaster.setLatitude(lonLat[1]);
                        yhDisaster.setLongitude(lonLat[0]);
                    }
                    yhDisaster.setYhConstructionPrice("");//造价
                    if (Objects.isNull(countryNoHouse.getDcmj())) {
                        yhDisaster.setYhConstructionScale("0");
                    } else {
                        yhDisaster.setYhConstructionScale(countryNoHouse.getDcmj().toString());//建设规模
                    }
//                yhDisaster.setYhProjectTask(CommonConstant.TYPE_COUNTRY_NO_HOUSE);//工程任务-建筑名称
                    String buildTime = countryNoHouse.getJznd();//建造年代
                    yhDisaster.setBuildingTimeDetails(buildTime);
                    if (StringUtils.isEmpty(buildTime)) {
                        buildTime = CommonConstant.BUILDTIME_NO;
                        yhDisaster.setBuildingTimeDetails("0");
                    } else {
                        switch (buildTime) {
                            case "1":
                            case "2":
                                buildTime = CommonConstant.BUILDTIME_1989;
                                break;
                            case "3":
                                buildTime = CommonConstant.BUILDTIME_1990;
                                break;
                            case "4":
                                buildTime = CommonConstant.BUILDTIME_2000;
                                break;
                            case "5":
                            case "6":
                                buildTime = CommonConstant.BUILDTIME_2011;
                                break;
                            default:
                                buildTime = CommonConstant.BUILDTIME_NO;
                                break;
                        }
                    }
                    yhDisaster.setYhBuildingTime(buildTime);
                    //抗震设防类别
                    // if (yhDisaster.getYhProjectType().equals("其他")) {
                    //     yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_III);
                    // } else {
                    //     yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_II);
                    // }
                    String jznd = countryNoHouse.getJznd();
                    if (yhDisaster.getYhProjectType().equals("大中小学校舍")) {
                        if (jznd.equals("1") || jznd.equals("2") || jznd.equals("3") || jznd.equals("4")) {
                            yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_III);
                        } else {
                            yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_II);
                        }
                    } else if (yhDisaster.getYhProjectType().equals("医疗卫生设施")) {
                        yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_II);
                    } else {
                        yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_III);
                    }
                    //原设防烈度
                    String yearthIntensity = null;
                    if (null == countryNoHouse.getKzsfqk()) {
                        yearthIntensity = CommonConstant.SFLD_N0;
                    } else {
                        switch (countryNoHouse.getKzsfqk()) {
                            // case "1":
                            //     yearthIntensity = CommonConstant.SFLD_6;
                            //     break;
                            // case "2":
                            //     yearthIntensity = CommonConstant.SFLD_70;
                            //     break;
                            // case "3":
                            //     yearthIntensity = CommonConstant.SFLD_82;
                            //     break;
                            // case "4":
                            //     yearthIntensity = CommonConstant.SFLD_94;
                            //     break;
                            case "2":
                                yearthIntensity = CommonConstant.SFLD_6;
                                break;
                            case "3":
                                yearthIntensity = CommonConstant.SFLD_70;
                                break;
                            case "5":
                                yearthIntensity = CommonConstant.SFLD_82;
                                break;
                            case "7":
                                yearthIntensity = CommonConstant.SFLD_94;
                                break;
                            default:
                                yearthIntensity = CommonConstant.SFLD_N0;
                        }
                    }
                    yhDisaster.setYhEarthIntensity(yearthIntensity);
                    //现抗震设防区划
                    String nowdata = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    yhDisaster.setYhNowEarthQh(nowdata);
                    yhDisaster.setYhFieldType(getSiteTypeFromLonLat(lonLat[0], lonLat[1], yhDisaster.getProvince()) + "类场地");//场地类别默认二类
                    //现存灾害
                    if ("1".equals(countryNoHouse.getYwlfbxqx())) {//有
                        if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SERIOUS);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_BIG);
                        }
                    } else {
                        if (CommonConstant.BUILDTIME_2011.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_NO);
                        } else if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_COMMON);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SLIGHT);
                        }
                    }
                    yhDisaster.setExtends1(CommonConstant.TYPE_COUNTRY_NO_HOUSE_CH);
                    yhDisaster.setExtends3(countryNoHouse.getFxpcDataidSjgl());
                    yhDisaster.setQualityResult("1");
                    yhDisaster.setReviewStatus("1");
                    yhDisaster.setYhCreatetime(countryNoHouse.getFxpcCreatetimeSjgl());
                    yhDisaster.setYhUpdatetime(countryNoHouse.getFxpcUpdatetimeSjgl());
                    yhDisaster.setCreateUserId(PlatformSessionUtils.getUserId());
                    yhDisaster.setIsValid("1");
                    yhDisaster.setCreateTime(new Date());
                    yhDisasterEntities.add(yhDisaster);
                    count++;
                    if (count % 10000 == 0) {
                        System.out.println("当前解析了: " + count + " 条数据");
                    }
                }
                Long end = System.currentTimeMillis();
                System.out.println("解析" + yhDisasterEntities.size() + "条数据================总用时：" + (end - start));
                if (yhDisasterEntities.size() < commitSize) {
                    yhDisasterDao.batchSave(yhDisasterEntities);
                } else {
                    int size = yhDisasterEntities.size() / commitSize;
                    if (yhDisasterEntities.size() % commitSize != 0) {
                        size++;
                    }
                    for (int i = 0; i < size; i++) {
                        List<YhDisasterEntity> subList = null;
                        if ((i + 1) * commitSize > yhDisasterEntities.size()) {
                            subList = yhDisasterEntities.subList(i * commitSize, yhDisasterEntities.size());
                            System.out.println("===========当前提交数据位置:  " + yhDisasterEntities.size());
                        } else {
                            subList = yhDisasterEntities.subList(i * commitSize, (i + 1) * commitSize);
                            System.out.println("===========当前提交数据位置:  " + (i + 1) * commitSize);
                        }
                        yhDisasterDao.batchSave(subList);
                    }
                }
                System.out.println("=======入库总用时：" + (System.currentTimeMillis() - end));
                logger.info("农村非住宅插入条数:{},重复数据:{},插入时间:{}", yhDisasterEntities.size(), newData.size() - yhDisasterEntities.size(), LocalDate.now());
            }
            newData.clear();
        }
        return RestResultData.ok();
    }


    /**
     * 市政桥梁
     *
     * @return
     */
    @Override
    public RestResultData shareDataBridge() {
        List<BridgeEntity> newData = null;
        List<BridgeEntity> updateData = null;
        // 日期格式yyyy-MM-dd ，为0则为当日，1则是全部数据,否则指定日期查询
        // List<String> list=Arrays.asList("110000","130000","140000","150000","210000","220000","230000","310000",
        //                 "320000","350000","360000","370000","410000","420000","430000","440000","450000","460000","530000",
        //                 "540000","610000","650000");
        // List<String> list=Arrays.asList("120000","330000","340000","500000","510000","520000","620000","630000","640000");
        // List<String> list=Arrays.asList("210000","220000","230000","310000",
        //         "320000","350000","360000","370000","410000","420000","430000","440000","450000","460000","530000",
        //         "540000","610000","650000");
        List<String> list = Arrays.asList("150000");
        for (String city1 : list) {
            if ("1".equals(begin)) {
                System.out.println("=============city1:" + city1);
                newData = bridgeBaseDao.findBridgeAll(city1);
            } else {
                LocalDate beginDate = null;
                LocalDate endDate = null;
                if ("0".equals(begin)) {
                    beginDate = LocalDate.now();
                    endDate = LocalDate.now();
                } else {
                    // 根据时间段查询数据
                    beginDate = LocalDate.parse(begin, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    endDate = LocalDate.parse(end, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                }
                newData = bridgeBaseDao.findBridgeAddByDate(beginDate, endDate);
                updateData = bridgeBaseDao.findBridgeUpdateByDate(beginDate, endDate);
            }
            if (CollectionUtils.isEmpty(newData) && CollectionUtils.isEmpty(updateData)) {
                return RestResultData.ok("城镇住宅没有数据更新");
            }
            //新增
            if (!CollectionUtils.isEmpty(newData)) {
                List<YhDisasterEntity> yhDisasterEntities = new ArrayList<>();
                int count = 0;
                Long start = System.currentTimeMillis();
                for (BridgeEntity bridge : newData) {
                    // YhDisasterEntity yhDisaster = new YhDisasterEntity01();
                    YhDisasterEntity yhDisaster = Entityutils.getEntity(bridge.getProvince());
                    if (yhDisaster == null) {
                        logger.info(bridge.getProvince(), "不合规范！");
                    }
                    yhDisaster.setId(UUID.randomUUID().toString().replace("-", ""));
                    yhDisaster.setYhCode(bridge.getBh());
                    yhDisaster.setYhUnit(bridge.getQlmc());
                    yhDisaster.setYhProjectType(CommonConstant.PROJECT_TYPE_BRIDGE);
                    //验重
                    // boolean isRRepeat = false;
                    // for (Object[] yhCodeAndYhProjectType : yhCodeAndYhProjectTypes) {
                    //     if (yhCodeAndYhProjectType[0].toString().equals(bridge.getBh()) &&
                    //             yhCodeAndYhProjectType[1].toString().equals(CommonConstant.PROJECT_TYPE_BRIDGE)) {
                    //         isRRepeat = true;
                    //         logger.info("市镇桥梁数据重复，重复编码:{}", bridge.getBh());
                    //         break;
                    //     }
                    // }
                    // if (isRRepeat) continue;
                    //yhDisaster.setProvince(divisionUtils.getDicisionNameByCode(cityHouse.getProvince()));
                    yhDisaster.setProvince(divisionInfoMap.get(bridge.getProvince()).toString());
                    String city = bridge.getCity();
                    if (city.equals("110100") || city.equals("120100") || city.equals("310100") || city.equals("500100")) {
                        city = city.substring(0, 2) + "0000";
                    }
                    yhDisaster.setCity(divisionInfoMap.get(city).toString());
                    yhDisaster.setArea(divisionInfoMap.get(bridge.getDistrict()).toString());
                    yhDisaster.setDetailedAddress(bridge.getTown());
                    String[] lonLat = {"0", "0"};
                    String distance = null;
                    if (Objects.isNull(bridge.getShape())) {
                    } else {
                        String str = bridge.getShape().toString();
                        lonLat = getLonLat(str);
                        //yhDisaster.setSpaceData(str.split(";")[1]);//空间数据
                        yhDisaster.setSpaceData(str);//空间数据
                        yhDisaster.setLatitude(lonLat[1]);
                        yhDisaster.setLongitude(lonLat[0]);
                        String[] split = str.substring(str.lastIndexOf("(") + 1, str.indexOf(")")).split(",");
                        distance = getDistance(split[0].split(" ")[0], split[0].split(" ")[1], split[split.length - 1].split(" ")[0], split[split.length - 1].split(" ")[1]);
                    }
                    yhDisaster.setYhConstructionPrice("");//造价
                    yhDisaster.setYhConstructionScale(distance);
//                yhDisaster.setYhProjectTask(CommonConstant.TYPE_CITY_HOUSE);//工程任务-建筑名称
                    String buildTime = "2000";//建造年代
                    yhDisaster.setBuildingTimeDetails(buildTime);
                    if (StringUtils.isEmpty(buildTime)) {
                        buildTime = CommonConstant.BUILDTIME_NO;
                        yhDisaster.setBuildingTimeDetails("0");
                    } else {
                        Integer integer = 0;
                        if (buildTime.length() >= 4) {
                            integer = Integer.valueOf(buildTime.substring(0, 4));
                        } else {
                            yhDisaster.setYhBuildingTime(CommonConstant.BUILDTIME_NO);
                        }
                        if (integer < 1989) {
                            buildTime = CommonConstant.BUILDTIME_1989;
                        } else if (integer >= 1990 && integer < 2000) {
                            buildTime = CommonConstant.BUILDTIME_1990;
                        } else if (integer >= 2000 && integer <= 2011) {
                            buildTime = CommonConstant.BUILDTIME_2000;
                        } else if (integer > 2011) {
                            buildTime = CommonConstant.BUILDTIME_2011;
                        } else {
                            buildTime = CommonConstant.BUILDTIME_NO;
                        }
                    }
                    yhDisaster.setYhBuildingTime(buildTime);
                    yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_II);//抗震设防类别
                    //原设防烈度
                    String yearthIntensity = null;
                    if (Objects.isNull(bridge.getKzld())) {
                        yearthIntensity = CommonConstant.SFLD_N0;
                    } else {
                        switch (bridge.getKzld()) {
                            case "2":
                                yearthIntensity = CommonConstant.SFLD_6;
                                break;
                            case "3":
                                yearthIntensity = CommonConstant.SFLD_70;
                                break;
                            case "5":
                                yearthIntensity = CommonConstant.SFLD_82;
                                break;
                            case "7":
                                yearthIntensity = CommonConstant.SFLD_94;
                                break;
                            default:
                                yearthIntensity = CommonConstant.SFLD_N0;
                        }
                    }
                    yhDisaster.setYhEarthIntensity(yearthIntensity);
                    //现设防烈度
                    String yhNowEarthQh = getFortificationIntensityFromLonLat(lonLat[0], lonLat[1]);
                    String extends5 = null;
                    if (!Objects.isNull(bridge.getXkzsfld())) {
                        switch (bridge.getXkzsfld()) {
                            case "1":
                                extends5 = CommonConstant.SFLD_N0;
                                break;
                            case "2":
                                extends5 = CommonConstant.SFLD_6;
                                break;
                            case "3":
                                extends5 = CommonConstant.SFLD_70;
                                break;
                            case "4":
                                extends5 = CommonConstant.SFLD_75;
                                break;
                            case "5":
                                extends5 = CommonConstant.SFLD_82;
                                break;
                            case "6":
                                extends5 = CommonConstant.SFLD_83;
                                break;
                            case "7":
                                extends5 = CommonConstant.SFLD_94;
                                break;
                            default:
                                extends5 = CommonConstant.SFLD_N0;
                        }
                    }
                    // if (Objects.isNull(bridge.getXkzsfld())) {
                    //     yhNowEarthQh = CommonConstant.SFLD_N0;
                    // } else {
                    //     switch (bridge.getXkzsfld()) {
                    //         case "2":
                    //             yhNowEarthQh = CommonConstant.SFLD_6;
                    //             break;
                    //         case "3":
                    //             yhNowEarthQh = CommonConstant.SFLD_70;
                    //             break;
                    //         case "5":
                    //             yhNowEarthQh = CommonConstant.SFLD_82;
                    //             break;
                    //         case "7":
                    //             yhNowEarthQh = CommonConstant.SFLD_94;
                    //             break;
                    //         default:
                    //             yhNowEarthQh = CommonConstant.SFLD_N0;
                    //     }
                    // }
                    yhDisaster.setYhNowEarthQh(yhNowEarthQh);
                    yhDisaster.setExtends5(extends5);
                    yhDisaster.setYhFieldType(getSiteTypeFromLonLat(lonLat[0], lonLat[1], yhDisaster.getProvince()) + "类场地");//场地类别默认二类
                    //现存灾害
                    if ("1".equals(bridge.getCztsfhp())) {//有
                        if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SERIOUS);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_BIG);
                        }
                    } else {
                        if (CommonConstant.BUILDTIME_2011.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_NO);
                        } else if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_COMMON);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SLIGHT);
                        }
                    }
                    yhDisaster.setExtends1(CommonConstant.TYPE_BRIDGE_CH);
                    yhDisaster.setExtends3(bridge.getFxpcDataidSjgl());
                    yhDisaster.setQualityResult("1");
                    yhDisaster.setReviewStatus("1");
                    yhDisaster.setYhCreatetime(bridge.getFxpcCreatetimeSjgl());
                    yhDisaster.setYhUpdatetime(bridge.getFxpcUpdatetimeSjgl());
                    yhDisaster.setCreateUserId(PlatformSessionUtils.getUserId());
                    yhDisaster.setIsValid("1");
                    yhDisaster.setCreateTime(new Date());
                    yhDisasterEntities.add(yhDisaster);
                    count++;
                    if (count % 10000 == 0) {
                        System.out.println("当前解析了: " + count + " 条数据");
                    }
                }
                Long end = System.currentTimeMillis();
                System.out.println("解析" + yhDisasterEntities.size() + "条数据================总用时：" + (end - start));
                if (yhDisasterEntities.size() < commitSize) {
                    yhDisasterDao.batchSave(yhDisasterEntities);
                } else {
                    int size = yhDisasterEntities.size() / commitSize;
                    if (yhDisasterEntities.size() % commitSize != 0) {
                        size++;
                    }
                    for (int i = 0; i < size; i++) {
                        List<YhDisasterEntity> subList = null;
                        if ((i + 1) * commitSize > yhDisasterEntities.size()) {
                            subList = yhDisasterEntities.subList(i * commitSize, yhDisasterEntities.size());
                            System.out.println("===========当前提交数据位置:  " + yhDisasterEntities.size());
                        } else {
                            subList = yhDisasterEntities.subList(i * commitSize, (i + 1) * commitSize);
                            System.out.println("===========当前提交数据位置:  " + (i + 1) * commitSize);
                        }
                        yhDisasterDao.batchSave(subList);
                    }
                }
                System.out.println("=======入库总用时：" + (System.currentTimeMillis() - end));
                logger.info("市政桥梁插入条数:{},插入时间:{}", yhDisasterEntities.size(), LocalDate.now());
            }
            newData.clear();
        }
        return RestResultData.ok();
    }


    /**
     * 供水厂
     *
     * @return
     */
    @Override
    public RestResultData shareDataWaterFacility() {
        List<WaterFacilityEntity> newData = null;
        List<WaterFacilityEntity> updateData = null;
        // 日期格式yyyy-MM-dd ，为0则为当日，1则是全部数据,否则指定日期查询
        // Arrays.asList("110000","130000","140000","150000","210000","220000","230000","310000",
        //                 "320000","350000","360000","370000","410000","420000","430000"/*,"440000"*/,"450000","460000","530000",
        //                 "540000","610000","650000","660000")
        for (String city1 : Arrays.asList("440000", "530000",
                "540000", "610000", "650000")) {
            if ("1".equals(begin)) {
                System.out.println("=============city1:" + city1);
                newData = waterFacilityBaseDao.findWaterFacilityAll(city1);
            } else {
                LocalDate beginDate = null;
                LocalDate endDate = null;
                if ("0".equals(begin)) {
                    beginDate = LocalDate.now();
                    endDate = LocalDate.now();
                } else {
                    // 根据时间段查询数据
                    beginDate = LocalDate.parse(begin, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                    endDate = LocalDate.parse(end, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                }
                newData = waterFacilityBaseDao.findWaterFacilityAddByDate(beginDate, endDate);
                updateData = waterFacilityBaseDao.findWaterFacilityUpdateByDate(beginDate, endDate);
            }
            if (CollectionUtils.isEmpty(newData) && CollectionUtils.isEmpty(updateData)) {
                return RestResultData.ok("====供水厂没有数据更新");
            }
            //新增
            if (!CollectionUtils.isEmpty(newData)) {
                // List<YhDisastersEntity> yhDisasterEntities = new ArrayList<>();
                List<YhDisasterEntity> yhDisasterEntities = new ArrayList<>();
                int count = 0;
                Long start = System.currentTimeMillis();
                for (WaterFacilityEntity water : newData) {
                    // YhDisasterEntity yhDisaster = new YhDisasterEntity01();
                    YhDisasterEntity yhDisaster = Entityutils.getEntity(water.getFxpcXzqhbmaSjgl());
                    yhDisaster.setId(UUID.randomUUID().toString().replace("-", ""));
                    yhDisaster.setYhCode(water.getBh());
                    yhDisaster.setYhUnit(water.getSsmc());
                    yhDisaster.setYhProjectType(CommonConstant.PROJECT_TYPE_WATER);
                    //List<YhDisastersEntity> disaster = yhDisasterBaseDao.findByYhCodeAndIsValidAndYhProjectType(cityHouse.getBh(), "1", yhDisaster.getYhProjectType());
                    //验重
                    // boolean isRRepeat = false;
                    // for (Object[] yhCodeAndYhProjectType : yhCodeAndYhProjectTypes) {
                    //     if (yhCodeAndYhProjectType[0].toString().equals(water.getBh()) &&
                    //             yhCodeAndYhProjectType[1].toString().equals(CommonConstant.PROJECT_TYPE_WATER)) {
                    //         isRRepeat = true;
                    //         //logger.info("供水厂数据重复，重复编码:{}", water.getBh());
                    //         break;
                    //     }
                    // }
                    // if (isRRepeat) continue;
                    //yhDisaster.setProvince(divisionUtils.getDicisionNameByCode(cityHouse.getProvince()));
                    yhDisaster.setProvince(divisionInfoMap.get(water.getFxpcXzqhbmaSjgl()).toString());
                    String city = water.getFxpcXzqhbmbSjgl();
                    if (city.equals("110100") || city.equals("120100") || city.equals("310100") || city.equals("500100")) {
                        city = city.substring(0, 2) + "0000";
                    }
                    yhDisaster.setCity(divisionInfoMap.get(city).toString());
                    yhDisaster.setArea(divisionInfoMap.get(water.getFxpcXzqhbmcSjgl()).toString());
                    yhDisaster.setDetailedAddress(water.getSsmc());
                    yhDisaster.setLatitude("0");
                    yhDisaster.setLongitude("0");
                    yhDisaster.setYhConstructionPrice("");//造价
                    if (Objects.isNull(water.getGm())) {
                        yhDisaster.setYhConstructionScale("0");
                    } else {
                        yhDisaster.setYhConstructionScale(water.getGm());//建设规模
                    }
                    //yhDisaster.setYhProjectTask(CommonConstant.TYPE_WATER_FACTILITY);//工程任务-建筑名称
                    String buildTime = "2000";//建造年代
                    yhDisaster.setBuildingTimeDetails("2000");
                    if (StringUtils.isEmpty(buildTime)) {
                        buildTime = CommonConstant.BUILDTIME_NO;
                        yhDisaster.setBuildingTimeDetails("0");
                    } else {
                        Integer integer = 0;
                        if (buildTime.length() >= 4) {
                            integer = Integer.valueOf(buildTime.substring(0, 4));
                        } else {
                            yhDisaster.setYhBuildingTime(CommonConstant.BUILDTIME_NO);
                        }
                        if (integer < 1989) {
                            buildTime = CommonConstant.BUILDTIME_1989;
                        } else if (integer >= 1990 && integer < 2000) {
                            buildTime = CommonConstant.BUILDTIME_1990;
                        } else if (integer >= 2000 && integer <= 2011) {
                            buildTime = CommonConstant.BUILDTIME_2000;
                        } else if (integer > 2011) {
                            buildTime = CommonConstant.BUILDTIME_2011;
                        } else {
                            buildTime = CommonConstant.BUILDTIME_NO;
                        }
                    }
                    yhDisaster.setYhBuildingTime(buildTime);
                    yhDisaster.setYhEarthFortification(CommonConstant.EARTHFORTIFICATION_II);//抗震设防类别
                    //原设防烈度
                    String yearthIntensity = null;
                    if (Objects.isNull(water.getKzsfld())) {
                        yearthIntensity = CommonConstant.SFLD_N0;
                    } else {
                        switch (water.getKzsfld()) {
                            case "2":
                                yearthIntensity = CommonConstant.SFLD_6;
                                break;
                            case "3":
                                yearthIntensity = CommonConstant.SFLD_70;
                                break;
                            case "5":
                                yearthIntensity = CommonConstant.SFLD_82;
                                break;
                            case "7":
                                yearthIntensity = CommonConstant.SFLD_94;
                                break;
                            default:
                                yearthIntensity = CommonConstant.SFLD_N0;
                        }
                    }
                    yhDisaster.setYhEarthIntensity(yearthIntensity);
                    //现设防烈度
                    String yhNowEarthQh = null;
                    if (Objects.isNull(water.getXkzsfld())) {
                        yhNowEarthQh = CommonConstant.SFLD_N0;
                    } else {
                        switch (water.getXkzsfld()) {
                            case "2":
                                yhNowEarthQh = CommonConstant.SFLD_6;
                                break;
                            case "3":
                                yhNowEarthQh = CommonConstant.SFLD_70;
                                break;
                            case "5":
                                yhNowEarthQh = CommonConstant.SFLD_82;
                                break;
                            case "7":
                                yhNowEarthQh = CommonConstant.SFLD_94;
                                break;
                            default:
                                yhNowEarthQh = CommonConstant.SFLD_N0;
                        }
                    }
                    //现抗震设防区划
                    yhDisaster.setYhNowEarthQh(yhNowEarthQh);
                    yhDisaster.setYhFieldType(CommonConstant.FIELDTYPE_Ⅱ);//场地类别默认二类
                    //现存灾害
                    if ("1".equals(water.getSfczbldz())) {//有
                        if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SERIOUS);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_BIG);
                        }
                    } else {
                        if (CommonConstant.BUILDTIME_2011.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_NO);
                        } else if (CommonConstant.BUILDTIME_NO.equals(yhDisaster.getYhBuildingTime()) ||
                                CommonConstant.BUILDTIME_1989.equals(yhDisaster.getYhBuildingTime())) {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_COMMON);
                        } else {
                            yhDisaster.setYhExistingVirus(CommonConstant.YWLFBXQX_SLIGHT);
                        }
                    }
                    yhDisaster.setExtends1(CommonConstant.TYPE_WATER_FACTILITY_CH);
                    yhDisaster.setExtends3(water.getFxpcDataidSjgl());
                    yhDisaster.setQualityResult("1");
                    yhDisaster.setReviewStatus("1");
                    yhDisaster.setYhCreatetime(water.getFxpcCreatetimeSjgl());
                    yhDisaster.setYhUpdatetime(water.getFxpcUpdatetimeSjgl());
                    yhDisaster.setCreateUserId(PlatformSessionUtils.getUserId());
                    yhDisaster.setIsValid("1");
                    yhDisaster.setCreateTime(new Date());
                    yhDisasterEntities.add(yhDisaster);
                }
                Long end = System.currentTimeMillis();
                System.out.println("解析" + yhDisasterEntities.size() + "条数据================总用时：" + (end - start));
                if (yhDisasterEntities.size() < commitSize) {
                    yhDisasterDao.batchSave(yhDisasterEntities);
                } else {
                    int size = yhDisasterEntities.size() / commitSize;
                    if (yhDisasterEntities.size() % commitSize != 0) {
                        size++;
                    }
                    for (int i = 0; i < size; i++) {
                        List<YhDisasterEntity> subList = null;
                        if ((i + 1) * commitSize > yhDisasterEntities.size()) {
                            subList = yhDisasterEntities.subList(i * commitSize, yhDisasterEntities.size());
                            System.out.println("===========当前提交数据位置:  " + yhDisasterEntities.size());
                        } else {
                            subList = yhDisasterEntities.subList(i * commitSize, (i + 1) * commitSize);
                            System.out.println("===========当前提交数据位置:  " + (i + 1) * commitSize);
                        }
                        yhDisasterDao.batchSave(subList);
                    }
                }
                System.out.println("=======入库总用时：" + (System.currentTimeMillis() - end));
                logger.info("供水厂插入条数:{},插入时间:{}", yhDisasterEntities.size(), LocalDate.now());
            }
            newData.clear();
        }
        return RestResultData.ok();
    }

    /**
     * 判断数据得工程类别
     *
     * @param projectType 工程类别
     * @param constrAppl  建筑用途
     * @return
     */
    private String getProjectType(String projectType, String constrAppl) {
        //1. 工程类别为空
        String resultProjectType = null;
        if (StringUtils.isEmpty(projectType)) {
            resultProjectType = getResultType(constrAppl);
        } else {
            //2. 工程类别不为空
            String id = yhDisasterBaseDao.findByProjectType(projectType);
            if (StringUtils.isEmpty(id)) {//未匹配到工程类别
                resultProjectType = getResultType(constrAppl);
            } else {
                resultProjectType = projectType;
            }
        }
        return resultProjectType;
    }

    //建筑用途获取工程类别
    public String getResultType(String constrAppl) {
        String resultProjectType = null;
        if (StringUtils.isEmpty(constrAppl)) {//建筑用途为空
            resultProjectType = "其他";
        } else {//建筑用途不为空
            if (constrAppl.contains("桥梁")) {
                constrAppl = "桥梁";
            } else if (constrAppl.contains("水厂")) {
                constrAppl = "水厂";
            }
            resultProjectType = yhDisasterBaseDao.findValueByConstrAppl(constrAppl);
            if (StringUtils.isEmpty(resultProjectType)) {
                resultProjectType = "其他";
            }
        }
        return resultProjectType;
    }


    //经纬度

    //距离
    public static double getDoubleDistance(String str) {
        double dd = 0.0;
        String[] splits1 = str.split("\\(|\\)");
        if (splits1.length > 0) {
            String[] splits2 = splits1[1].split(",");
            if (splits2.length > 0) {
                for (int i = 0; i < splits2.length - 1; i++) {
                    String[] splits3 = splits2[i].split(" ");
                    String[] splits4 = splits2[i + 1].split(" ");
                    if (splits3.length == 2 && splits4.length == 2) {
                        dd += Double.parseDouble(getDistance(splits3[0], splits3[1], splits4[0], splits4[1]));
                    }
                }
                /**/
            }
        }
        return dd;
    }

    private static double EARTH_RADIUS = 6378.137;

    private static double rad(double d) {
        return d * Math.PI / 180.0;
    }

    /**
     * 根据两个位置的经纬度，来计算两地的距离（单位为KM）
     * 参数为String类型
     *
     * @return
     */
    private static String getDistance(String lng1Str, String lat1Str, String lng2Str, String lat2Str) {
        Double lat1 = Double.parseDouble(lat1Str);
        Double lng1 = Double.parseDouble(lng1Str);
        Double lat2 = Double.parseDouble(lat2Str);
        Double lng2 = Double.parseDouble(lng2Str);

        double radLat1 = rad(lat1);
        double radLat2 = rad(lat2);
        double difference = radLat1 - radLat2;
        double mdifference = rad(lng1) - rad(lng2);
        double distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(difference / 2), 2)
                + Math.cos(radLat1) * Math.cos(radLat2)
                * Math.pow(Math.sin(mdifference / 2), 2)));
        distance = distance * EARTH_RADIUS * 1000;
        distance = Math.round(distance * 10000) / 10000;
        String distanceStr = distance + "";
        distanceStr = distanceStr.substring(0, distanceStr.indexOf("."));

        return distanceStr;
    }

    //经纬度
    private String[] getLonLat(String str) {
        String[] result = new String[2];
        str = str.replace("(((", "#");
        str = str.replace("((", "#");
        str = str.replace("(", "#");
        str = str.replace(")))", "#");
        str = str.replace("))", "#");
        str = str.replace(")", "#");
        String[] splits1 = str.split("#");
        if (splits1.length > 0) {
            String[] splits2 = splits1[1].split(",");
            if (splits2.length > 0) {
                String[] splits3 = splits2[0].split(" ");
                if (splits3.length == 2) {
                    result[0] = splits3[0];
                    result[1] = splits3[1];
                }
            }
        }
        return result;
    }

    /**
     * 判断现抗震设防烈度方法
     *
     * @param lon
     * @param lat
     * @return
     */
    public String getFortificationIntensityFromLonLat(String lon, String lat) {
        Point2D.Double point = new Point2D.Double();
        point.setLocation(Double.parseDouble(lon), Double.parseDouble(lat));
        String type = CommonConstant.SFLD_70;
        Set<Map.Entry<List, String>> entries = fiveMapPGAdatas.entrySet();
        for (Map.Entry<List, String> entry : entries) {
            boolean isin = isInPolygon(point, entry.getKey());
            if (isin) {
                type = entry.getValue();
                break;
            }
        }
        return type;
    }

    /**
     * 判断场地类型方法
     *
     * @param lon
     * @param lat
     * @return
     */
    public String getSiteTypeFromLonLat(String lon, String lat, String province) {
        if ("0".equals(lon)) {
            return "Ⅱ";
        }
        if (InActiveRange(lon, lat, province)) {
            return "Ⅴ";
        }
        Point2D.Double point = new Point2D.Double();
        point.setLocation(Double.parseDouble(lon), Double.parseDouble(lat));
        String type = "Ⅱ";
        //Set<Map.Entry<List,String>> entries = sitetypes.entrySet();
        HashMap<List, String> listStringHashMap = sitetypesAll.get(province);
        Set<Map.Entry<List, String>> entries = listStringHashMap.entrySet();
        for (Map.Entry<List, String> entry : entries) {
            boolean isin = isInPolygon(point, entry.getKey());
            if (isin) {
                type = entry.getValue();
                break;
            }
        }
        if ("水体".equals(type)) {
            type = "Ⅱ";
        }
        if ("Ⅰ0".equals(type)) {
            type = "Ⅰ";
        }
        return type;
    }

    private boolean InActiveRange(String lon, String lat, String province) {
        double d1 = Double.parseDouble(lon);
        double l1 = Double.parseDouble(lat);
        if (activespacedatas.containsKey(province)) {
            List<String[]> strings = activespacedatas.get(province);
            for (String[] lonlats : strings) {
                double d2 = Double.parseDouble(lonlats[0]);
                double l2 = Double.parseDouble(lonlats[1]);
                if (Distance(d1, l1, d2, l2) <= 10000) {
                    return true;
                }
            }
        }
        return false;
    }

    //计算两点之间的距离

    /**
     * 计算地球上任意两点(经纬度)距离
     *
     * @param long1 第一点经度
     * @param lat1  第一点纬度
     * @param long2 第二点经度
     * @param lat2  第二点纬度
     * @return 返回距离 单位：米
     */
    private double Distance(double long1, double lat1, double long2,
                            double lat2) {
        double a, b, R;
        R = 6378137; // 地球半径
        lat1 = lat1 * Math.PI / 180.0;
        lat2 = lat2 * Math.PI / 180.0;
        a = lat1 - lat2;
        b = (long1 - long2) * Math.PI / 180.0;
        double d;
        double sa2, sb2;
        sa2 = Math.sin(a / 2.0);
        sb2 = Math.sin(b / 2.0);
        d = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2));
        return d;
    }


    public static void setBaseDatas(String type, String sourceData) {
        String pstr = sourceData;
        pstr = pstr.replace(")), ((", "#");
        pstr = pstr.replace("), (", "#");
        String[] ss1 = pstr.split("\\(");
        if (ss1.length >= 2) {
            String[] ss2 = ss1[ss1.length - 1].split("\\)");
            if (ss2.length <= 2) {
                String[] spacedatas = ss2[0].replace(",", ";").replace("; ", ";").replace(" ", ",").split("#");
                List<Point2D.Double> points = new ArrayList<>();
                for (int i = 0; i < spacedatas.length; i++) {
                    String[] lonlats = spacedatas[i].split(";");
                    if (lonlats.length > 0) {
                        for (int j = 0; j < lonlats.length; j++) {
                            String[] lonlat = lonlats[j].split(",");
                            if (lonlat.length != 2) {
                                continue;
                            }
                            Point2D.Double point = new Point2D.Double();
                            point.setLocation(Double.parseDouble(lonlat[0]), Double.parseDouble(lonlat[1]));
                            points.add(point);
                        }
                        //Point2D.Double point=
                    }
                }
                sitetypes.put(points, type);
            }
        }
    }

    /**
     * 判断点是否在多边形内
     *
     * @param point 测试点
     * @param pts   多边形的点
     * @return boolean
     * @throws
     * @Title: IsPointInPoly
     * @Description: TODO()
     */
    public boolean isInPolygon(Point2D.Double point, List<Point2D.Double> pts) {

        int N = pts.size();
        boolean boundOrVertex = true;
        int intersectCount = 0;//交叉点数量
        double precision = 2e-10; //浮点类型计算时候与0比较时候的容差
        Point2D.Double p1, p2;//临近顶点
        Point2D.Double p = point; //当前点

        p1 = pts.get(0);
        for (int i = 1; i <= N; ++i) {
            if (p.equals(p1)) {
                return boundOrVertex;
            }

            p2 = pts.get(i % N);
            if (p.x < Math.min(p1.x, p2.x) || p.x > Math.max(p1.x, p2.x)) {
                p1 = p2;
                continue;
            }

            //射线穿过算法
            if (p.x > Math.min(p1.x, p2.x) && p.x < Math.max(p1.x, p2.x)) {
                if (p.y <= Math.max(p1.y, p2.y)) {
                    if (p1.x == p2.x && p.y >= Math.min(p1.y, p2.y)) {
                        return boundOrVertex;
                    }

                    if (p1.y == p2.y) {
                        if (p1.y == p.y) {
                            return boundOrVertex;
                        } else {
                            ++intersectCount;
                        }
                    } else {
                        double xinters = (p.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
                        if (Math.abs(p.y - xinters) < precision) {
                            return boundOrVertex;
                        }

                        if (p.y < xinters) {
                            ++intersectCount;
                        }
                    }
                }
            } else {
                if (p.x == p2.x && p.y <= p2.y) {
                    Point2D.Double p3 = pts.get((i + 1) % N);
                    if (p.x >= Math.min(p1.x, p3.x) && p.x <= Math.max(p1.x, p3.x)) {
                        ++intersectCount;
                    } else {
                        intersectCount += 2;
                    }
                }
            }
            p1 = p2;
        }
        if (intersectCount % 2 == 0) {//偶数在多边形外
            return false;
        } else { //奇数在多边形内
            return true;
        }
    }

}
